package sedh.project

import grails.test.*

class AlocadorMunSerIntTests extends GroovyTestCase {
	
	def alocMunSer1, alocMunSer2
	
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCriaESalvaAlocacoes() {
		
		def s1 = new Servico(nome: "Servico1", descricao: "Descricao1").save()
		def m1 = new Municipio(nome : "municipio5", habitantes: 100000).save()
		
		def s2 = new Servico(nome: "Servico2", descricao: "Descricao2").save()
		def m2 = new Municipio(nome : "municipio6", habitantes: 1000000).save()
		
		alocMunSer1 = new AlocadorMunSer(municipio: m1, servico: s1, telefone: 35412213, responsavel: "Responsavel3", familias: 100)
		alocMunSer2 = new AlocadorMunSer(municipio: m2, servico: s2, telefone: 35411090, responsavel: "Responsavel4", familias: 100)
		
		alocMunSer1.save()
		alocMunSer2.save()
		
		assertNotNull(alocMunSer1)
		assertNotNull(alocMunSer2)
		
		assertEquals 2, AlocadorMunSer.count()
    }
	
	void testDeletaTodosOsAlocados() {
		def all = AlocadorMunSer.getAll()
		
		for (AlocadorMunSer aloc : all) {
			aloc.delete(flush : true)
		}
		
		assertEquals 0, AlocadorMunSer.count()
	}
}
